//
//  TabBarController.m
//  GymJT
//
//  Created by    🐯 on 16/9/8.
//  Copyright © 2016年 张炫赫. All rights reserved.
//

#import "TabBarController.h"
#import "NavigationViewController.h"
#import "UIColor+Hex.h"
#import "UIImage+Color.h"

#import "RW_HomeViewController.h"
#import "RW_FuncViewController.h"
#import "RW_UserSingleViewController.h"
#import "RW_MineViewController.h"
#import "UIImage+WLDark.h"

#import "RW_PushPlayersTools.h"

@interface TabBarController ()<UITabBarDelegate,UITabBarControllerDelegate>

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.WLTabBar.itemTitleColor = [UIColor colorWithHexString:@"666666"];
    self.WLTabBar.itemSelectedTitleColor = [UIColor colorWithHexString:@"5564BE"];
    [self setUpAllChildViewController];
    
    [[RW_PushPlayersTools singletonMod] addPlayIconFromVc:self];
}

-(void)changeSelectIndex:(NSInteger)index{
    self.selectedIndex = index;
}
#pragma mark - XXTabBarDelegate Method
- (BOOL)tabBar:(WLTabBar *)tabBarView didSelectedItemFrom:(NSInteger)from to:(NSInteger)to {
    self.selectedIndex = to;
    return true;
}
#pragma mark - 添加所有的子控制器
- (void)setUpAllChildViewController{
    NSMutableArray *array = [NSMutableArray array];
    {
        RW_HomeViewController *vc = [[RW_HomeViewController alloc]init];
        [array addObject:[self setupCpint:vc title:@"音频" imageName:@"tabbar_audio" selectImageName:@"tabbar_audio"]];
    }
//    {
//        RW_FuncViewController *vc = [[RW_FuncViewController alloc]init];
//        [array addObject:[self setupCpint:vc title:@"播放器" imageName:@"tb_mine_unsel" selectImageName:@"tb_mine_sel" changeColor:NO]];
//    }
    {
        RW_UserSingleViewController *vc = [[RW_UserSingleViewController alloc]init];
        [array addObject:[self setupCpint:vc title:@"收藏" imageName:@"tabbar_collection" selectImageName:@"tabbar_collection"]];
    }
    {
        RW_MineViewController *vc = [[RW_MineViewController alloc]init];
        [array addObject:[self setupCpint:vc title:@"我的" imageName:@"tabbar_mine" selectImageName:@"tabbar_mine"]];
    }
    
    self.viewControllers = array;
}

#pragma mark - 添加一个子控制器
-(NavigationViewController *)setupCpint:(UIViewController *)contller
                                       title:(NSString *)title
                                   imageName:(NSString *)imageName
                             selectImageName:(NSString *)selectImageName{
    contller.tabBarItem.image = [UIImage svgName:imageName tintColor:self.WLTabBar.itemTitleColor];
    contller.tabBarItem.selectedImage = [UIImage svgName:selectImageName];
    
    contller.title = title;
    NavigationViewController *nav=[[NavigationViewController alloc] initWithRootViewController:contller];
    return nav;
}



@end
